﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace CharToImage
{
    class ImageProcess
    {
        public static Bitmap CreateFromChar_48X48(string word)
        {
            Bitmap bmp = new Bitmap(48, 48);
            Graphics g = Graphics.FromImage((Image)bmp);
            Font f = new Font("SimHei", 35, FontStyle.Regular);
            Brush b = new SolidBrush(Color.Black);
            g.DrawString(word, f, b, -8, -1);
            f.Dispose();
            b.Dispose();
            return bmp;
        }
        public static void SaveToFile(string fileName, int size, Bitmap bmp)
        {
            Bitmap result = new Bitmap(size, size);
            using (Graphics graphics = Graphics.FromImage(result))
            {
                //set the resize quality modes to high quality
                graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                //draw the image into the target bitmap
                graphics.DrawImage(bmp, 0, 0, result.Width, result.Height);
            }

            result.Save(fileName);
            result.Dispose();
        }
    }
}
